// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mybase/base/tool/file/FFile.dart';
import 'dart:convert';


///创建待翻译的文件
Future<void> main() async {

  String mapFile = "/Users/os/spotify/spotify/assets/language/all.json";
  String targetFile = "/Users/os/spotify/spotify/test/create/language/translate/md5.json";

  String mapFileContent = await FFile.readAsString(mapFile);
  Map<String,dynamic> targetMap = {};
  Map<String,dynamic> mapObj = json.decode(mapFileContent);

  convertFile("", mapObj,targetMap);

  //print("内容如下\n ${targetMap.toString()}");
  String content = json.encode(targetMap);
  bool success = await FFile.writeContentByPath(filePath: targetFile, content: content,mode: FileMode.write);
  print("写入状态: $success");
}

void convertFile(String outKey, Map<String,dynamic> mapObj,Map<String,dynamic> targetMap){

  mapObj.forEach((key, value) {

    String inKey = md5.convert(utf8.encode("$outKey$key")).toString();
    if (value is String) {
      targetMap[inKey] = value;
    }  else if (value is Map) {
      Map<String,dynamic> valueMap = value as Map<String,dynamic>;
      convertFile(inKey, valueMap, targetMap);
    }
  });
}


